﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Presenters;
using University.Workshop.WinApp.Product;
using University.Workshop.Model;
using University.Workshop.WinApp.Clients;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.Reporting.WinForms;
using System.IO;

namespace University.Workshop.WinApp
{
    public partial class ReportSales : Form, IReportSale
    {
        PresenterReportSale report;
        ReportSaleVariables variables = ReportSaleVariables.Instance;
        UserLogOn user = UserLogOn.Instance;
        public ReportSales()
        {
            InitializeComponent();
            report = new PresenterReportSale(this);
        }
        #region IReportSale Members
        public string ClientId
        {
            get
            {
                return textClient.Text;
            }
            set
            {
                textClient.Text=value;
            }
        }
        public string ProductId
        {
            get
            {
                return textProduct.Text;
            }
            set
            {
                textProduct.Text = value ;
            }
        }
        public bool VisibleClient
        {
            get
            {
                return visibleClient.Checked;
            }
            set
            {
                client.Visible=value;
            }
        }
        public bool VisibleProduct
        {
            get
            {
                return visibleProduct.Checked;
            }
            set
            {
                product.Visible=value;
            }
        }
        public DateTime DateInit
        {
            get
            {
                return new DateTime(dateInit.Value.Year,dateInit.Value.Month,dateInit.Value.Day,0,0,0);
            }
            
        }
        public DateTime DateEnd
        {
            get
            {
                return new DateTime(dateEnd.Value.Year, dateEnd.Value.Month, dateEnd.Value.Day, 23, 59, 59); ;
            }
            
        }
        public string FlagProduct
        {
            get { return variables.IdProduct; }
        }
        public string FlagClient
        {
            get { return variables.IdClient; }
        }
        public bool VisibilityReportViewer
        {
          
            set { panelReport.Visible = value; }
        }
        public DataTable DataReport
        {
            get
            {
                return (DataTable) dataGridReportProduct.DataSource;
            }
            set
            {
                dataGridReportProduct.DataSource = value;
            }
        }
        public string UserId { get { return user.Id.ToString(); } }
        public string ClientReport { get { return labelClientId.Text; } set { labelClientId.Text = value; } }
        public string ProductReport { get { return labelProductId.Text; } set { labelProductId.Text = value; } }
        #endregion
        private void Checked(object sender, EventArgs e)
        {
            report.ReportState();
        }
        private void SearchProduct_Click(object sender, EventArgs e)
        {
            variables.IdProduct = "BrowserProductReportSale";
            FormProductView productCode = new FormProductView();
            productCode.ShowDialog();
            report.SetProduct();

        }
        private void searchCliente_Click(object sender, EventArgs e)
        {
            variables.IdClient = "BrowserClientReportSale";
            FormClientsView clientCode = new FormClientsView();
            clientCode.ShowDialog();
            report.SetClient();
        }
        private void buttonReportGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                report.GenerateReport();
                
                
            }
            catch (BusinessException be)
            {
                MessageBox.Show(this, "", be.Message, MessageBoxButtons.OK,
                        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.RightAlign);
            }
            catch (DataAccessException de)
            {
                MessageBox.Show(this, de.Message, "Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.RightAlign);
            }
        }
        private void buttonSearchReport_Click(object sender, EventArgs e)
        {
            try
            {
                report.SearchReport();

            }
            catch (BusinessException be)
            {
                MessageBox.Show(this, be.Message, "Error de Parametros", MessageBoxButtons.OK,
                        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.RightAlign);
            }
            catch (DataAccessException de)
            {
                MessageBox.Show(this, de.Message, "Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.RightAlign);
            }
        }

       
    }
}
